package com.kevis.demo.es;

import org.apache.http.HttpHost;
import org.elasticsearch.client.ElasticsearchClient;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.client.indices.CreateIndexRequest;
import org.elasticsearch.client.indices.CreateIndexResponse;

import java.io.IOException;

public class ConnectElasticsearch {
    public static void connect(ElasticsearchTask task) {
        // 创建客户端对象
        try (RestHighLevelClient client = new RestHighLevelClient(
                RestClient.builder(new HttpHost("192.168.152.134", 9200, "http"))
        )) {
            task.doSomething(client);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
